package com.dingreading.cloud.admin.controller;

import com.dingreading.cloud.admin.service.StoreFunctionService;
import com.dingreading.cloud.common.base.R;
import com.dingreading.cloud.common.util.PageUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;

@RestController
@RequestMapping("/system/storeFunction")
@Api(tags = "总部-门店个性化功能")
public class StoreFunctionController {

    @Resource
    private StoreFunctionService storeFunctionService;

    @ApiOperation(value = "分页列表")
    @PostMapping(value = "/pageList", produces = "application/json; charset=UTF-8")
    public R<Object> pageList(
            @ApiParam(value = "分页公共类") PageUtil pageUtil,
            @ApiParam(value = "总部员工uid") @RequestParam(value = "headStaffUid") String headStaffUid,
            @ApiParam(value = "总部员工名") @RequestParam(value = "headStaffName") String headStaffName,
            @ApiParam(value = "功能名称") @RequestParam(value = "keyword", required = false) String keyword,
            @ApiParam(value = "默认状态(0.关闭，1.开启)") @RequestParam(value = "status", required = false) Integer status,
            @ApiParam(value = "启用状态(0.关闭，1.开启)") @RequestParam(value = "enabled", required = false) Integer enabled
    ) {
        return storeFunctionService.pageList(pageUtil, headStaffUid, headStaffName, keyword, status, enabled);
    }

    @ApiOperation(value = "获取当前功能信息")
    @PostMapping(value = "/get", produces = "application/json; charset=UTF-8")
    public R<Object> get(
            @ApiParam(value = "总部员工uid") @RequestParam(value = "headStaffUid") String headStaffUid,
            @ApiParam(value = "总部员工名") @RequestParam(value = "headStaffName") String headStaffName,
            @ApiParam(value = "功能uid") @RequestParam(value = "uid") String uid
    ) {
        return storeFunctionService.get(headStaffUid, headStaffName, uid);
    }

    @ApiOperation(value = "添加/修改")
    @PostMapping(value = "/add", produces = "application/json; charset=UTF-8")
    public R<Object> add(
            @ApiParam(value = "总部员工uid") @RequestParam(value = "headStaffUid") String headStaffUid,
            @ApiParam(value = "总部员工名") @RequestParam(value = "headStaffName") String headStaffName,
            @ApiParam(value = "功能名称") @RequestParam(value = "name") String name,
            @ApiParam(value = "功能标识") @RequestParam(value = "identify") String identify,
            @ApiParam(value = "默认状态(0.关闭，1.开启)") @RequestParam(value = "status") Integer status,
            @ApiParam(value = "功能uid") @RequestParam(value = "uid", required = false) String uid
    ) {
        return storeFunctionService.add(headStaffUid, headStaffName, name, identify, status, uid);
    }

    @ApiOperation(value = "更新启用状态")
    @PostMapping(value = "/updateEnabled", produces = "application/json; charset=UTF-8")
    public R<Object> updateEnabled(
            @ApiParam(value = "总部员工uid") @RequestParam(value = "headStaffUid") String headStaffUid,
            @ApiParam(value = "总部员工名") @RequestParam(value = "headStaffName") String headStaffName,
            @ApiParam(value = "功能uid") @RequestParam(value = "uid") String uid,
            @ApiParam(value = "启用状态 0.禁用 1.启用") @RequestParam(value = "enabled") Integer enabled
    ) {
        return storeFunctionService.updateEnabled(headStaffUid, headStaffName, uid, enabled);
    }
}
